import ISendMsg from './form/ISendMsg'
import ISupportApp from './form/ISupportApp'

// 是否支持：微信小程序
// @ts-ignore
let supportFlag = window.__wxjs_environment === 'miniprogram'

// @ts-ignore
const wxApi: { miniProgram: Record<Function> } = window.wx

// 给微信小程序发送消息
function sendMsg(form: ISendMsg) {
  form.url = window.location.href

  // if (form.code === 1) {
  //   // 1 登录
  //   wxApi.miniProgram.navigateTo({
  //     url: `/pages/login/login?data=${JSON.stringify(form)}`,
  //   })
  // } else {
  wxApi.miniProgram.navigateTo({
    url: `/pages/webView/webView?data=${JSON.stringify(form)}`,
  })
  // }
}

const install: ISupportApp = {
  type: 1,
  supportFlag,
  sendMsg,
}

export default install
